<?php
namespace app\models;

class Fans extends IModel {
    public $table = 't_fans';

    public function fansNumber($uid) {
        return $this->count('uid=' . $uid);
    }

    public function followsNumber($uid) {
        return $this->count('fans_uid=' . $uid);
    }

    public function follow($uid, $fansUid) {
        $ret = $this->count('uid=' . $uid . ' and fans_uid=' . $fansUid);

        if($ret > 0) {
            return;
        }

        $data = ['uid' => $uid, 'fans_uid' => $fansUid, 'post_time' => time()];
        $this->insert($data);
    }

    public function unFollow($uid, $fansUid) {
        $this->deleteByCondition('uid=' . $uid . ' and fans_uid=' . $fansUid);
    }
}
